﻿#include "ComClientStatusWidget.h"


#pragma execution_character_set("utf-8")
ComClientOneStatusWidget::ComClientOneStatusWidget(const QString &name, QWidget *parent)
{
    QGridLayout* gLayout = new QGridLayout();
    this->setLayout(gLayout);
    lblStatus = new QLabel("未连接");
    gLayout->addWidget(new QLabel(name), 0, 0);
    gLayout->addWidget(lblStatus, 0, 1);
}

void ComClientOneStatusWidget::setText(const QString &status)
{
    lblStatus->setText(status);
}

ComClientStatusWidget::ComClientStatusWidget(const QString& title, QWidget *parent)
    : QGroupBox{title, parent}
{
    this->setMinimumWidth(200);
    mLayout = new QVBoxLayout();
    this->setLayout(mLayout);
}

void ComClientStatusWidget::removeOne(QString name)
{
    ComClientOneStatusWidget* wgt = mMapWgtComClientStatus.take(name);
    wgt->deleteLater();
    wgt = nullptr;
}

void ComClientStatusWidget::setStatus(QString name, QString status)
{
    mMapWgtComClientStatus.value(name)->setText(status);
}

void ComClientStatusWidget::addOne(QString name)
{
    ComClientOneStatusWidget* wgt = new ComClientOneStatusWidget(name);
    mMapWgtComClientStatus.insert(name, wgt);
    mLayout->addWidget(wgt);
}
